package com.xc.quickstart.infrastructure.ds;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

@Slf4j
public class DynamicDataSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        String dataSourceType = DataSourceContext.getDataSourceType();

        if (StringUtils.isEmpty(dataSourceType)) {
            dataSourceType = DataSourceEnum.TCPOI_WRITE.getModule();
        }

        log.debug("====switch to db:{}", dataSourceType);
        return dataSourceType;
    }
}